<?php

require_once BaseUtil::getModulePath("base")  .  '/forms/BaseForm.php';
require_once   BaseUtil::getModulePath("base")  .  '/validate/Unique.php';

class AdminForm extends BaseForm {
    public function __construct ($departments,$roles)
    {
        parent::__construct();
	    $this->setAction(HttpUtil::getUrl("admin", "subadd"));
        // username
        $name = new Zend_Form_Element_Text('name');
        $name->setLabel($this->translate->_('userName'));
        $name->addFilter("StringTrim");
        $name->setRequired(true);
        // passwrod
        $password = new Zend_Form_Element_Password('password');
        $password->setLabel($this->translate->_('password'));
        $password->addFilter("StringTrim");
        $password->setRequired(true);
        //$password->addValidator();
        //email
        $email = new Zend_Form_Element_Text('email');
        $email->setLabel($this->translate->_('userEmail'));
        $email->addFilter("StringTrim");
        $email->setRequired(true);
        $email->addValidator('EmailAddress');

        //unique validate
        $validUnique = new MyValid_Unique();
        $validUnique->setTableName('admins');
        $validUnique->setFieldName('email');
        $email->addValidator($validUnique);

        //role
        $role = new Zend_Form_Element_Select("role");
        $role->setLabel($this->translate->_('role'));
        $role->setMultiOptions($roles);
        $role->setRequired(true);
        //departments
        $depChkbox = new Zend_Form_Element_MultiCheckbox("department");
        $depChkbox->setLabel($this->translate->_('department'));
        $depChkbox->setRequired(true);
        $depChkbox->setMultiOptions($departments);

        $this->addElements(array($name,$password,$email,$role,$depChkbox));

        $this->setElementDecorators(array(
            'ViewHelper',
            array(array('div' => 'HtmlTag'), array('tag' => 'div',"class" => "form_element")),
        ));

    }
}